package com.briup.cms.exception;

import com.briup.cms.util.Result;
import com.briup.cms.util.ResultCode;
import com.briup.cms.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e){
        log.error("全局异常处理");
        e.printStackTrace();
        if (e instanceof CustomerException){
            return ResultUtil.error(((CustomerException) e).getCode());
        }
        return ResultUtil.success(ResultCode.SERVER_INTER_ERROR);
    }
}
